package com.lv.LvTourismModel.dao;
import com.aqgj.util.BaseDaoImpl;
import com.lv.LvTourismModel.bean.LvTourismModel;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @ClassName LvTourismModelDao
 * @JDK 1.5
 * @author
 * @date
 */
@Repository("LvTourismModelDao")
public class LvTourismModelDao extends BaseDaoImpl<LvTourismModel> {
    /**
     * 修改
     * @param lvTourismModel 实体bean
     * @return 0.失败，1.成功
     */
    public String update(LvTourismModel lvTourismModel) {
        this.getHibernateTemplate().saveOrUpdate(lvTourismModel);
        if (lvTourismModel.getId() != null) {
            return "1";
        }
        return "0";
    }

    /**
     * 搜索旅游模板列表
     * @param sql sql语句
     * @return
     */
    public List<LvTourismModel> search(String sql) {
        List<LvTourismModel> list = this.currentSession().createNativeQuery(sql,LvTourismModel.class).getResultList();
        return list;
    }

    /**
     * 删除
     * @param id 旅游模板id
     * @param transportId 公司id
     * @return
     */
    public String delete(String id, String transportId) {
        String sql = "delete from lv_tourism_model where 1=1";
        if (id != null) {
            sql += " and id='" + id + "'";
        }
        if (transportId != null) {
            sql += " and fk_transport_id='" + transportId + "'";
        }
        if (this.currentSession().createNativeQuery(sql).executeUpdate() >= 0) {
            return "1";
        }
        return "0";
    }
}